//=============================================================================
// PepperPotFire - Fires a swarm of homing rockets.
//=============================================================================
class PepperPotFire extends TFProjectileFire;

var PepperPot Gun;
var bool bDumbFire;
var() sound SeekingBeep;

function PostBeginPlay()
{
	Super.PostBeginPlay();
	Gun = PepperPot(Owner);
}

//Allows player to force rockets to ignore Darts if the fire button is held down for a while.
function ModeTick(float dt)
{
	//Force bots to fire right away normally.
	if(Gun.bBotForceFire && HoldTime > 0.1)
		bIsFiring = false;

	if(HoldTime > 0.5)
	{
		bDumbFire = true;
		bIsFiring = false;
	}

	Super.ModeTick(dt);
}

function DoFireEffect()
{
	local Vector StartProj, RealStartProj, StartTrace, X,Y,Z;
	local Rotator Aim;
	local Vector HitLocation, HitNormal;
	local Actor Other;
	local int p;
	local PepperPotRocket proj;

	Instigator.MakeNoise(1.0);
	Weapon.GetViewAxes(X,Y,Z);

	StartTrace = Instigator.Location + Instigator.EyePosition();
	StartProj = StartTrace + X * ProjSpawnOffset.X + Z * ProjSpawnOffset.Z;

	if(!Weapon.WeaponCentered())
		StartProj = StartProj + Weapon.Hand * Y * ProjSpawnOffset.Y;

	//check if projectile would spawn through a wall and adjust start location accordingly
	Other = Trace(HitLocation, HitNormal, StartProj, StartTrace, false);
	if (Other != None)
	{
		StartProj = HitLocation;
	}
    
	Aim = AdjustAim(StartProj, AimError);

	for (p = 0; p < ProjPerFire; p++)
	{
		if(p == 1)
			RealStartProj = StartProj + Y * 12;
		else if(p == 2)
			RealStartProj = StartProj - Y * 12;
		else if(p == 3)
			RealStartProj = StartProj + Z * 12;
		else if(p == 4)
			RealStartProj = StartProj - Z * 12;
		else if(p == 5)
		{
			RealStartProj = StartProj + Y * 16;
			RealStartProj += Z * 16;
		}
		else if(p == 6)
		{
			RealStartProj = StartProj - Y * 16;
			RealStartProj += Z * 16;
		}
		else if(p == 7)
		{
			RealStartProj = StartProj + Y * 16;
			RealStartProj -= Z * 16;
		}
		else if(p == 8)
		{
			RealStartProj = StartProj - Y * 16;
			RealStartProj -= Z * 16;
		}
		else
			RealStartProj = StartProj;

		proj = PepperPotRocket(SpawnProjectile(RealStartProj, Aim));

		if(proj != None && !bDumbFire)
			proj.Target = Gun.Dart;
	}

	if(!bDumbFire && Gun.Dart != None)
		Weapon.PlaySound(SeekingBeep, SLOT_Misc, TransientSoundVolume,,,, false);

	bDumbFire = false;
}

defaultproperties
{
     SeekingBeep=Sound'GeneralAmbience.beep4'
     ProjPerFire=9
     ProjSpawnOffset=(X=25.000000,Y=6.000000,Z=-6.000000)
     bSplashDamage=True
     bRecommendSplashDamage=True
     bFireOnRelease=True
     FireSound=Sound'TFMedia.PepperPot.PepperPotFire'
     FireForce="RocketLauncherFire"
     FireRate=0.900000
     AmmoClass=Class'taskforces.PepperPotAmmo'
     AmmoPerFire=1
     ShakeRotTime=2.000000
     ShakeOffsetMag=(X=-20.000000)
     ShakeOffsetRate=(X=-1000.000000)
     ShakeOffsetTime=2.000000
     ProjectileClass=Class'taskforces.PepperPotRocket'
     BotRefireRate=0.900000
}
